Crate image_texel

source ·
Expand description

Matrix

An image compatible with transmuting its byte content.

This library is strictly no_std, and aims to offer utilities to represent and share image buffers between platforms, byte representations, and processing methods. It acknowledges that, in a typical image pipeline, there may exist many valid but competing representations:

  • A reader that decodes pixel representations into bytes (in network endian).
  • Some other decoder that returns Vec<[[u16; 3]]> of native endian data.
  • Some library transformation that consumes &[Rgb<u16>].
  • Some SIMD usage that requires data is passed as &[Simd<u16, 16>].
  • Some GPU buffer written by a highly-aligned, and line-padded &[u8].
  • Some GPU buffer containing texels of 4×2 pixels each.
  • A shared buffer that represents pixels as &[[AtomicU8; 4]].
  • A non-planar layout that splits channels to different pages.

This crate offers the language to ensure that as many uses cases as possible can share allocations, or even offer zero-copy conversion.

Usage

use image_texel::Matrix;
let mut image = Matrix::<[u8; 4]>::with_width_and_height(400, 400);

// Draw a bright red line.
for i in 0..400 {
    // Assign color as u8-RGBA
    image[(i, i)] = [0xFF, 0x00, 0x00, 0xFF];
}

// Encode to network endian.
let mut encoded = image.transmute::<u32>();
encoded
    .as_mut_slice()
    .iter_mut()
    .for_each(|p| *p = p.to_be());

// Send the raw bytes
send_over_network(encoded.as_bytes());

Re-exports

pub use self::image::Image;

Modules

Defines the Image container, with flexibly type-safe layout.
A module for different pixel layouts.
Constants for predefined texel types.

Structs

Error representation for a failed buffer reuse.
A 2d, width-major matrix of pixels.
Error representation for a failed buffer reuse for an image.
Marker struct to denote a texel type.
A reinterpretable vector for an array of texels.

Traits

Describes a type which can represent a Texel and for which this is statically known.